package com.ruoyi.system.outto.game.impl;

import cn.hutool.core.io.resource.ClassPathResource;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.system.model.domain.AccountInfo;
import com.ruoyi.system.model.domain.InfoImg;
import com.ruoyi.system.model.domain.SalePartner;
import com.ruoyi.system.model.mapper.AccountInfoMapper;
import com.ruoyi.system.model.mapper.InfoImgMapper;
import com.ruoyi.system.model.mapper.SuprAuthMapper;
import com.ruoyi.system.outto.core.LCConstant;
import com.ruoyi.system.outto.core.MapUntils;
import com.ruoyi.system.outto.core.OutUrlConstant;
import com.ruoyi.system.outto.core.RegionalCovert;
import com.ruoyi.system.outto.game.CommonApi;
import com.ruoyi.system.outto.game.LCAPI;
import com.ruoyi.system.outto.game.ZHUANAPI;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.*;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author lz
 * @version 1.0
 * @date 2022/6/5 16:19
 */
@Slf4j
@Service
public class ZHUANAPIImpl implements ZHUANAPI {

    @Resource
    private InfoImgMapper infoImgMapper;
    @Resource
    private AccountInfoMapper accountInfoMapper;
    @Resource
    private SuprAuthMapper suprAuthMapper;
    @Resource
    private CommonApi commonApi;
    @Value("${desc.title}")
    private String descTitle;
    private SalePartner salePartner;

    private Boolean flag = true;

    @Override
    public AjaxResult addGame(AccountInfo accountInfo, Long userId, SalePartner salePartner) {

//        {"respCode":0,"respData":"{\"zzProductId\":1592069759299503616}","errorMsg":"null","errMsg":""}

        this.salePartner = salePartner;
        Map<String, Object> result = new HashMap<>();
        Map<String, Object> params = params(accountInfo, "publish");
        log.info("转转添加接口请求参数={}", JSONObject.toJSONString(params));
        String response = HttpUtils.sendPost(salePartner.getTwoOther(), JSONObject.toJSONString(params), "application/json");
        log.info("转转添加接口返回参数={}", response);
        JSONObject resultJson = JSONObject.parseObject(response);
        if (!"0".equals(resultJson.getString("respCode"))) {
            result.put("code", 500);
        } else {
            Long id = accountInfo.getId();
            String respData = resultJson.getString("respData");
            JSONObject jsonObject = JSONObject.parseObject(respData);
            AccountInfo info = accountInfoMapper.selectAccountInfoById(id);
            info.setZid(jsonObject.getString("zzProductId"));
            accountInfoMapper.updateAccountInfo(info);
            result.put("code", 200);
        }

        result.put("req", JSONObject.toJSONString(params));
        result.put("res", response);
        result.put("msg", resultJson.getString("respData"));
        return AjaxResult.success(result);
    }

    @Override
    public AjaxResult editGame(AccountInfo accountInfo, Long userId, SalePartner salePartner) {
        this.salePartner = salePartner;
        Map<String, Object> result = new HashMap<>();
        Map<String, Object> params = params(accountInfo, "update");
        log.info("转转编辑接口请求参数={}", JSONObject.toJSONString(params));
        String response = HttpUtils.sendPost(salePartner.getTwoOther(), JSONObject.toJSONString(params), "application/json");
        log.info("转转编辑接口返回参数={}", response);
        JSONObject resultJson = JSONObject.parseObject(response);

        if (!"0".equals(resultJson.getString("respCode"))) {
            result.put("code", 500);
        } else {
            result.put("code", 200);
        }

        result.put("req", JSONObject.toJSONString(params));
        result.put("res", response);
        result.put("msg", resultJson.getString("respData"));
        return AjaxResult.success(result);
    }


    private Map<String, Object> params(AccountInfo accountInfo, String type) {

        if (!"offshelf".equals(type)){
            String level = accountInfo.getLevel();
            String[] noTaong = {"无二次","包人脸"};
            if (flag){
                if (Arrays.asList(noTaong).contains(level)){
                    throw new GlobalException(level + "，转转平台不卖");
                }
            }
        }

//        String[] noTaong = {"无二次","包人脸"};
//        if (Arrays.asList(noTaong).contains(accountInfo.getLevel())){
//            throw new GlobalException(accountInfo.getLevel() + "，转转平台不卖");
//        }


        Map<String, Object> params = new TreeMap<>();
        params.put("businessId", salePartner.getOther());
        params.put("timeStamp", new Date().getTime() / 100);

        params.put("cmd", type);

        StringBuilder joinStr = new StringBuilder();
        joinStr.append("businessid=").append(params.get("businessId"))
                .append("&cmd=").append(params.get("cmd"))
                .append("&timestamp=").append(params.get("timeStamp"))
                .append(salePartner.getSaleKey());
        String signature = DigestUtils.md5Hex(joinStr.toString()).toLowerCase();

        params.put("signature", signature);

        Integer game = getGame(accountInfo.getType());
        if (Objects.isNull(game) && (!"offshelf".equals(type))) {
            throw new GlobalException("当前游戏暂不支持");
        }

        params.put("categoryId", game);
        if (StringUtils.isNotEmpty(accountInfo.getZid()) & !"publish".equals(type) && accountInfo.getZid().length() < 10){
            throw new GlobalException("转转ID格式不对");
        }
        params.put("zzProductId", accountInfo.getZid());

        InfoImg infoImg = new InfoImg();
        infoImg.setInfoId(accountInfo.getId());
        infoImg.setType(Constants.STR_1);
        List<InfoImg> infoImgs = infoImgMapper.selectInfoImgList(infoImg);
        String imgs = "";
        if (!CollectionUtils.isEmpty(infoImgs)) {
            imgs = infoImgs.stream().map(i -> i.getImgUrl()).collect(Collectors.joining("|"));
        }
        if (StringUtils.isEmpty(imgs)) {
            imgs = LCConstant.defaultImg;
        }

        JSONObject commonData = new JSONObject();
        String des = accountInfo.getDes();
        if (accountInfo.getDes().length() > 50) {
            des = accountInfo.getDes().substring(0, 50);
        }
        commonData.put("title", "xyr" + accountInfo.getId() + "|" + des);
        commonData.put("content", "xyr" + accountInfo.getId() + "|" + accountInfo.getDes());
        commonData.put("pic", imgs);
        commonData.put("state", 1);

        BigDecimal bigDecimal = commonApi.addPrice(accountInfo.getPrice(), salePartner.getSeleep());
        commonApi.setPrice(bigDecimal,accountInfo.getId(),salePartner);
        commonData.put("sellPrice", bigDecimal.multiply(new BigDecimal(100)));


        params.put("commonData", commonData);
        JSONObject jsonObject = new JSONObject();
        if (!Objects.equals("offshelf", type)) {
            jsonObject = extendData(accountInfo);
        }
        params.put("extendData", jsonObject);

        String cover = MapUntils.getCover(params);
        cover = cover + "key=" + this.salePartner.getSaleKey();
        String sign = DigestUtils.md5Hex(cover).toUpperCase();
        log.info("sign={}", sign);
        params.put("sign", sign);
        return params;
    }


    @Override
    public AjaxResult delGame(AccountInfo accountInfo, SalePartner sa) {

        this.flag = false;
        this.salePartner = sa;
        Map<String, Object> result = new HashMap<>();
        Map<String, Object> params = params(accountInfo, "offshelf");
        log.info("转转删除接口请求参数={}", JSONObject.toJSONString(params));
        String response = HttpUtils.sendPost(salePartner.getTwoOther(), JSONObject.toJSONString(params), "application/json");
        log.info("转转删除接口返回参数={}", response);
        JSONObject resultJson = JSONObject.parseObject(response);

        if (!"0".equals(resultJson.getString("respCode"))) {
            result.put("code", 500);
        } else {
            result.put("code", 200);
        }

        result.put("req", JSONObject.toJSONString(params));
        result.put("res", response);
        result.put("msg", resultJson.getString("respData"));
        return AjaxResult.success(result);
    }


    private JSONObject extendData(AccountInfo accountInfo) {

        JSONObject extendData = new JSONObject();
        List<JSONObject> dataList = new ArrayList<>();


        String zhuanzhuanStr = readTxtFile();

        JSONObject jsonObject = JSONObject.parseObject(zhuanzhuanStr);
        String records = jsonObject.getString("RECORDS");
        JSONArray objects = JSONObject.parseArray(records);

        JSONObject resourceData = new JSONObject();
        resourceData.put("paramId", 10727);
        resourceData.put("valueId", 1138289);
        dataList.add(resourceData);

        String des = accountInfo.getDes();


        if (Objects.equals("王者荣耀", accountInfo.getType())) {


            JSONObject areaData = new JSONObject();
            areaData.put("paramId", 17);
            if (Objects.equals("安卓Q", accountInfo.getRegional())) {
                areaData.put("valueId", 123001);
            }
            if (Objects.equals("安卓WX", accountInfo.getRegional())) {
                areaData.put("valueId", 123002);
            }
            if (Objects.equals("苹果Q", accountInfo.getRegional())) {
                areaData.put("valueId", 123003);
            }
            if (Objects.equals("苹果WX", accountInfo.getRegional())) {
                areaData.put("valueId", 123004);
            }
            dataList.add(areaData);

            JSONObject accountType = new JSONObject();
            accountType.put("paramId", 23);
            accountType.put("valueId", 123009);
            dataList.add(accountType);


            JSONObject shiming = new JSONObject();
            shiming.put("paramId", 7217);
            if (flag){
                if (Arrays.asList(LCConstant.haveTwoList).contains(accountInfo.getLevel())) {
                    shiming.put("valueId", 123007);
                } else {
                    throw new GlobalException("无二次、包人脸，转转平台不卖");
                }
            }

            dataList.add(shiming);

            JSONObject heros = new JSONObject();
            heros.put("paramId", "24");
            heros.put("valueId", accountInfo.getHeroes());
            dataList.add(heros);

            JSONObject skins = new JSONObject();
            skins.put("paramId", "25");
            skins.put("valueId", accountInfo.getSkins());
            dataList.add(skins);


            if (StringUtils.isNotEmpty(accountInfo.getCampId())) {
                JSONObject yind = new JSONObject();
                yind.put("paramId", "10600");
                yind.put("valueId", accountInfo.getCampId());
                dataList.add(yind);
            }


            String guizudengj = "";
            String tsyx = "";
            String xypf = "";
            String dcpf = "";
            String cspf = "";
            String sspf = "";
            String yzpf = "";


            for (Object object : objects) {

                String string = JSONObject.toJSONString(object);

                JSONObject reglese = JSONObject.parseObject(string);

                String brand_name = reglese.getString("brand_name");

                if (Objects.equals("王者荣耀", brand_name)) {

                    String param_name = reglese.getString("param_name");

                    if (Objects.equals("贵族等级", param_name)) {
                        String value_text = reglese.getString("value_text");
                        if (des.contains(value_text)) {
                            String value_id = reglese.getString("value_id");

                            guizudengj = guizudengj + value_id + "|";
                        }
                    }

                    if (Objects.equals("特色英雄", param_name)) {
                        String value_text = reglese.getString("value_text");
                        if (StringUtils.isNotEmpty(value_text)) {
                            String[] split = value_text.split("-");
                            if (split.length > 1) {
                                if (des.contains(split[1])) {
                                    String value_id = reglese.getString("value_id");
                                    tsyx = tsyx + value_id + "|";
                                    continue;
                                }
                            }
                        }

                    }
                    if (Objects.equals("星元皮肤", param_name)) {
                        String value_text = reglese.getString("value_text");
                        if (StringUtils.isNotEmpty(value_text)) {
                            String[] split = value_text.split("-");
                            if (split.length > 1) {
                                if (des.contains(split[1])) {
                                    String value_id = reglese.getString("value_id");
                                    xypf = xypf + value_id + "|";
                                    continue;
                                }
                            }
                        }
                    }
                    if (Objects.equals("典藏皮肤", param_name)) {
                        String value_text = reglese.getString("value_text");

                        if (StringUtils.isNotEmpty(value_text)) {
                            String[] split = value_text.split("-");
                            if (split.length > 1) {
                                if (des.contains(split[1])) {
                                    String value_id = reglese.getString("value_id");
                                    dcpf = dcpf + value_id + "|";
                                    continue;
                                }
                            }
                        }
                    }
                    if (Objects.equals("传说皮肤", param_name)) {
                        String value_text = reglese.getString("value_text");
                        String[] split = value_text.split("-");
                        if (split.length > 1) {
                            if (des.contains(split[1])) {
                                String value_id = reglese.getString("value_id");
                                cspf = cspf + value_id + "|";
                                continue;
                            }
                        }
                    }
                    if (Objects.equals("史诗皮肤", param_name)) {
                        String value_text = reglese.getString("value_text");

                        String[] split = value_text.split("-");
                        if (split.length > 1) {
                            if (des.contains(split[1])) {
                                String value_id = reglese.getString("value_id");
                                sspf = sspf + value_id + "|";
                                continue;
                            }
                        }
                    }
                    if (Objects.equals("勇者皮肤", param_name)) {
                        String value_text = reglese.getString("value_text");

                        String[] split = value_text.split("-");
                        if (split.length > 0) {
                            if (des.contains(split[1])) {
                                String value_id = reglese.getString("value_id");
                                yzpf = yzpf + value_id + "|";
                                continue;
                            }
                        }
                    }
                }
            }


            JSONObject yzpfdata = new JSONObject();
            if (StringUtils.isNotEmpty(yzpf)) {
                yzpf = yzpf.substring(0, yzpf.length() - 1);
                yzpfdata.put("paramId", "11449");
                yzpfdata.put("valueId", yzpf);
                dataList.add(yzpfdata);

            }
            JSONObject sspfdata = new JSONObject();
            if (StringUtils.isNotEmpty(sspf)) {
                sspf = sspf.substring(0, sspf.length() - 1);
                sspfdata.put("paramId", "11448");
                sspfdata.put("valueId", sspf);
                dataList.add(sspfdata);
            }


            JSONObject cspfData = new JSONObject();
            if (StringUtils.isNotEmpty(cspf)) {
                cspf = cspf.substring(0, cspf.length() - 1);
                cspfData.put("paramId", "11447");
                cspfData.put("valueId", cspf);
                dataList.add(cspfData);
            }


            JSONObject dcpfdata = new JSONObject();
            if (StringUtils.isNotEmpty(dcpf)) {
                dcpf = dcpf.substring(0, dcpf.length() - 1);
                dcpfdata.put("paramId", "10736");
                dcpfdata.put("valueId", dcpf);
                dataList.add(dcpfdata);
            }


            JSONObject data = new JSONObject();
            if (StringUtils.isNotEmpty(guizudengj)) {
                guizudengj = guizudengj.substring(0, guizudengj.length() - 1);
                data.put("paramId", "10874");
                data.put("valueId", guizudengj);
                dataList.add(data);
            }


            JSONObject tsyxdata = new JSONObject();
            if (StringUtils.isNotEmpty(tsyx)) {
                tsyx = tsyx.substring(0, tsyx.length() - 1);
                tsyxdata.put("paramId", "7229");
                tsyxdata.put("valueId", tsyx);
                dataList.add(tsyxdata);
            }


            JSONObject xypfdata = new JSONObject();
            if (StringUtils.isNotEmpty(tsyx)) {
                tsyx = tsyx.substring(0, tsyx.length() - 1);
                xypfdata.put("paramId", "7232");
                xypfdata.put("valueId", tsyx);
                dataList.add(xypfdata);
            }

        }
        if (Objects.equals("和平精英", accountInfo.getType())) {

            JSONObject areaData = new JSONObject();
            areaData.put("paramId", 17);
            if (Objects.equals("安卓Q", accountInfo.getRegional())) {
                areaData.put("valueId", 123001);
            }
            if (Objects.equals("安卓WX", accountInfo.getRegional())) {
                areaData.put("valueId", 123002);
            }
            if (Objects.equals("苹果Q", accountInfo.getRegional())) {
                areaData.put("valueId", 123003);
            }
            if (Objects.equals("苹果WX", accountInfo.getRegional())) {
                areaData.put("valueId", 123004);
            }
            dataList.add(areaData);

            JSONObject accountType = new JSONObject();
            accountType.put("paramId", 23);
            accountType.put("valueId", 123009);
            dataList.add(accountType);

            JSONObject level = new JSONObject();
            level.put("paramId", 7174);
            level.put("valueId", 102);
            dataList.add(level);

            JSONObject shiming = new JSONObject();
            shiming.put("paramId", 7217);
            if (flag){
                if (Arrays.asList(LCConstant.haveTwoList).contains(accountInfo.getLevel())) {
                    shiming.put("valueId", 123007);
                } else {
                    throw new GlobalException("无二次、包人脸，转转平台不卖");
                }
            }

            dataList.add(shiming);

            JSONObject heros = new JSONObject();
            heros.put("paramId", "7528");
            heros.put("valueId", accountInfo.getGuns());
            dataList.add(heros);

            JSONObject skins = new JSONObject();
            skins.put("paramId", "7529");
            skins.put("valueId", accountInfo.getSuit());
            dataList.add(skins);


            if (StringUtils.isNotEmpty(accountInfo.getCampId())) {
                JSONObject yind = new JSONObject();
                yind.put("paramId", "10600");
                yind.put("valueId", accountInfo.getCampId());
                dataList.add(yind);
            }


            String xyqx = "";
            String tsyx = "";
            String xyzj = "";
            String xyfxq = "";
            String yztz = "";

            for (Object object : objects) {

                String string = JSONObject.toJSONString(object);

                JSONObject reglese = JSONObject.parseObject(string);

                String brand_name = reglese.getString("brand_name");

                if (Objects.equals("和平精英", brand_name)) {


                    String param_name = reglese.getString("param_name");

                    if (Objects.equals("稀有枪械", param_name)) {
                        String value_text = reglese.getString("value_text");
                        if (des.contains(value_text)) {
                            String value_id = reglese.getString("value_id");

                            xyqx = xyqx + value_id + "|";
                        }
                    }

                    if (Objects.equals("特色英雄", param_name)) {
                        String value_text = reglese.getString("value_text");
                        if (des.contains(value_text)) {
                            String value_id = reglese.getString("value_id");

                            tsyx = tsyx + value_id + "|";

                        }
                    }
                    if (Objects.equals("稀有载具", param_name)) {
                        String value_text = reglese.getString("value_text");
                        if (des.contains(value_text)) {
                            String value_id = reglese.getString("value_id");

                            xyzj = xyzj + value_id + "|";

                        }
                    }
                    if (Objects.equals("稀有飞行器", param_name)) {
                        String value_text = reglese.getString("value_text");
                        if (des.contains(value_text)) {
                            String value_id = reglese.getString("value_id");

                            xyfxq = xyfxq + value_id + "|";

                        }
                    }
                    if (Objects.equals("优质套装", param_name)) {
                        String value_text = reglese.getString("value_text");
                        if (des.contains(value_text)) {
                            String value_id = reglese.getString("value_id");
                            yztz = yztz + value_id + "|";
                        }
                    }
                }
            }


            JSONObject data = new JSONObject();
            if (StringUtils.isNotEmpty(xyqx)) {
                xyqx = xyqx.substring(0, xyqx.length() - 1);
                data.put("paramId", "10741");
                data.put("valueId", xyqx);
                dataList.add(data);

            }

            JSONObject tsyxdata = new JSONObject();
            if (StringUtils.isNotEmpty(tsyx)) {
                tsyx = tsyx.substring(0, tsyx.length() - 1);
                tsyxdata.put("paramId", "7229");
                tsyxdata.put("valueId", tsyx);
                dataList.add(tsyxdata);
            }


            JSONObject xyzjdata = new JSONObject();
            if (StringUtils.isNotEmpty(xyzj)) {
                xyzj = xyzj.substring(0, xyzj.length() - 1);
                xyzjdata.put("paramId", "10742");
                xyzjdata.put("valueId", xyzj);
                dataList.add(xyzjdata);
            }


            JSONObject xyfxqdata = new JSONObject();
            if (StringUtils.isNotEmpty(xyfxq)) {
                xyfxq = xyfxq.substring(0, xyfxq.length() - 1);
                xyfxqdata.put("paramId", "10743");
                xyfxqdata.put("valueId", xyfxq);
                dataList.add(xyfxqdata);
            }


            JSONObject yztzdata = new JSONObject();
            if (StringUtils.isNotEmpty(yztz)) {
                yztz = yztz.substring(0, yztz.length() - 1);
                yztzdata.put("paramId", "10744");
                yztzdata.put("valueId", yztz);
                dataList.add(yztzdata);
            }


        }
        if (Objects.equals("原神", accountInfo.getType())) {


            JSONObject areaData = new JSONObject();
            areaData.put("paramId", 23);
            areaData.put("valueId", 1120920);
            dataList.add(areaData);


            JSONObject shiming = new JSONObject();
            shiming.put("paramId", 11096);
            if (flag){
                if (!LCConstant.kehuanMial.equals(accountInfo.getLevel())) {
                    throw new GlobalException("不能更换邮箱的，转转平台不卖");
                }else {
                    shiming.put("valueId", 1162661);
                }
            }


            dataList.add(shiming);
            String xxjs = "";
            String wxwqi = "";

            for (Object object : objects) {


                String string = JSONObject.toJSONString(object);

                JSONObject reglese = JSONObject.parseObject(string);


                String brand_name = reglese.getString("brand_name");

                if (Objects.equals("原神", brand_name)) {

                    String param_name = reglese.getString("param_name");

                    if (Objects.equals("五星角色", param_name)) {
                        String value_text = reglese.getString("value_text");
                        if (des.contains(value_text)) {
                            String value_id = reglese.getString("value_id");

                            xxjs = xxjs + value_id + "|";

                        }
                    }

                    if (Objects.equals("五星武器", param_name)) {
                        String value_text = reglese.getString("value_text");
                        if (des.contains(value_text)) {
                            String value_id = reglese.getString("value_id");

                            wxwqi = wxwqi + value_id + "|";

                        }
                    }
                }
            }

            JSONObject data = new JSONObject();
            if (StringUtils.isNotEmpty(xxjs)) {
                xxjs = xxjs.substring(0, xxjs.length() - 1);
            }
            data.put("paramId", "10547");
            data.put("valueId", xxjs);
            dataList.add(data);

            JSONObject wxwqidata = new JSONObject();
            if (StringUtils.isNotEmpty(wxwqi)) {
                wxwqi = wxwqi.substring(0, wxwqi.length() - 1);
            }
            wxwqidata.put("paramId", "10548");
            wxwqidata.put("valueId", wxwqi);
            dataList.add(wxwqidata);
        }
        if (Objects.equals("CF端游", accountInfo.getType())) {


            JSONObject areaData = new JSONObject();
            areaData.put("paramId", 23);
            areaData.put("valueId", 1120920);
            dataList.add(areaData);


            JSONObject shiming = new JSONObject();
            shiming.put("paramId", 27);
            shiming.put("valueId", accountInfo.getRegional());
            dataList.add(shiming);

            String xxjs = "";

            for (Object object : objects) {

                String string = JSONObject.toJSONString(object);

                JSONObject reglese = JSONObject.parseObject(string);

                String brand_name = reglese.getString("brand_name");

                if (Objects.equals("穿越火线", brand_name)) {


                    String param_name = reglese.getString("param_name");

                    if (Objects.equals("账号特色", param_name)) {
                        String value_text = reglese.getString("value_text");
                        if (des.contains(value_text)) {
                            String value_id = reglese.getString("value_id");

                            xxjs = xxjs + value_id + "|";

                        }
                    }
                }
            }
            JSONObject data = new JSONObject();
            if (StringUtils.isNotEmpty(xxjs)) {
                xxjs = xxjs.substring(0, xxjs.length() - 1);
            }
            data.put("paramId", "7074");
            data.put("valueId", xxjs);
            dataList.add(data);
        }
        if (Objects.equals("光遇", accountInfo.getType())) {
            for (Object object : objects) {
                String string = JSONObject.toJSONString(object);
                JSONObject reglese = JSONObject.parseObject(string);
                String brand_name = reglese.getString("brand_name");
                if (Objects.equals("光遇", brand_name)) {
                    JSONObject regional = new JSONObject();
                    regional.put("paramId", 23);
                    if ("苹果网易邮箱".equals(accountInfo.getRegional())) {
                        regional.put("valueId", 123016);
                    }
                    if ("安卓网易邮箱".equals(accountInfo.getRegional())) {
                        regional.put("valueId", 123020);
                    }
                    if ("华为渠道服".equals(accountInfo.getRegional())) {
                        regional.put("valueId", 1081612);
                    }
                    if ("小米渠道服".equals(accountInfo.getRegional())) {
                        regional.put("valueId", 1081613);
                    }
                    if ("OPPO渠道服".equals(accountInfo.getRegional())) {
                        regional.put("valueId", 1082832);
                    }
                    if ("VIVO渠道服".equals(accountInfo.getRegional())) {
                        regional.put("valueId", 1100756);
                    }
                    dataList.add(regional);
                }
            }
        }
        if (Objects.equals("英雄联盟", accountInfo.getType())) {

            JSONObject regional = new JSONObject();
            regional.put("paramId", 23);
            regional.put("valueId", 123009);
            dataList.add(regional);

            JSONObject heros = new JSONObject();
            heros.put("paramId", "24");
            heros.put("valueId", accountInfo.getHeroes());
            dataList.add(heros);

            JSONObject skins = new JSONObject();
            skins.put("paramId", "25");
            skins.put("valueId", accountInfo.getSkins());
            dataList.add(skins);

            JSONObject re = new JSONObject();
            re.put("paramId", "27");
            re.put("valueId", accountInfo.getRegional());
            dataList.add(re);

            String xxjs = "";

            for (Object object : objects) {

                String string = JSONObject.toJSONString(object);
                JSONObject reglese = JSONObject.parseObject(string);
                String brand_name = reglese.getString("brand_name");
                if (Objects.equals("英雄联盟", brand_name)) {

                    String param_name = reglese.getString("param_name");

                    if (Objects.equals("服务器名称", param_name)) {
                        String value_text = reglese.getString("value_text");
                        if (des.contains(value_text)) {
                            String value_id = reglese.getString("value_id");
                            xxjs = xxjs + value_id + "|";

                        }
                    }
                }
            }

            JSONObject data = new JSONObject();
            if (StringUtils.isNotEmpty(xxjs)) {
                xxjs = xxjs.substring(0, xxjs.length() - 1);
            }
            data.put("paramId", "6989");
            data.put("valueId", xxjs);
            dataList.add(data);
        }

        if (Objects.equals("火影忍者", accountInfo.getType())) {

            JSONObject areaData = new JSONObject();
            areaData.put("paramId", 17);
            if (Objects.equals("安卓Q", accountInfo.getRegional())) {
                areaData.put("valueId", 123001);
            }
            if (Objects.equals("安卓WX", accountInfo.getRegional())) {
                areaData.put("valueId", 123002);
            }
            if (Objects.equals("苹果Q", accountInfo.getRegional())) {
                areaData.put("valueId", 123003);
            }
            if (Objects.equals("苹果WX", accountInfo.getRegional())) {
                areaData.put("valueId", 123004);
            }
            dataList.add(areaData);


            JSONObject shiming = new JSONObject();
            shiming.put("paramId", 19);
            if (LCConstant.rezhengMial.equals(accountInfo.getLevel())) {
                shiming.put("valueId", 123007);
            } else if (LCConstant.nobanggMial.equals(accountInfo.getLevel())) {
                shiming.put("valueId", 123008);
            }
            dataList.add(shiming);

            String xxjs = "";
            String yzpf = "";

            for (Object object : objects) {


                String string = JSONObject.toJSONString(object);

                JSONObject reglese = JSONObject.parseObject(string);

                String brand_name = reglese.getString("brand_name");

                if (Objects.equals("火影忍者", brand_name)) {


                    String param_name = reglese.getString("param_name");

                    if (Objects.equals("S忍", param_name)) {
                        String value_text = reglese.getString("value_text");
                        if (des.contains(value_text)) {
                            String value_id = reglese.getString("value_id");

                            xxjs = xxjs + value_id + "|";

                        }
                    }
                    if (Objects.equals("A忍", param_name)) {
                        String value_text = reglese.getString("value_text");
                        if (des.contains(value_text)) {
                            String value_id = reglese.getString("value_id");
                            yzpf = yzpf + value_id + "|";
                        }
                    }
                }
            }
            JSONObject data = new JSONObject();
            data.put("paramId", "10750");
            data.put("valueId", xxjs);
            dataList.add(data);

            JSONObject yzpfdata = new JSONObject();
            yzpfdata.put("paramId", "10751");
            yzpfdata.put("valueId", yzpf);
            dataList.add(yzpfdata);
        }
        if (Objects.equals("CF手游", accountInfo.getType())) {

            JSONObject areaData = new JSONObject();
            areaData.put("paramId", 17);
            if (Objects.equals("安卓Q", accountInfo.getRegional())) {
                areaData.put("valueId", 123001);
            }
            if (Objects.equals("安卓WX", accountInfo.getRegional())) {
                areaData.put("valueId", 123002);
            }
            if (Objects.equals("苹果Q", accountInfo.getRegional())) {
                areaData.put("valueId", 123003);
            }
            if (Objects.equals("苹果WX", accountInfo.getRegional())) {
                areaData.put("valueId", 123004);
            }
            dataList.add(areaData);

            String xxjs = "";
            String yzpf = "";
            String sss = "";
            String vss = "";

            for (Object object : objects) {

                String string = JSONObject.toJSONString(object);

                JSONObject reglese = JSONObject.parseObject(string);

                String brand_name = reglese.getString("brand_name");

                if (Objects.equals("穿越火线：枪战王者", brand_name)) {


                    String param_name = reglese.getString("param_name");

                    if (Objects.equals("账号特色", param_name)) {
                        String value_text = reglese.getString("value_text");
                        if (des.contains(value_text)) {
                            String value_id = reglese.getString("value_id");

                            xxjs = xxjs + value_id + "|";

                        }
                    }
                    if (Objects.equals("武器", param_name)) {
                        String value_text = reglese.getString("value_text");
                        if (des.contains(value_text)) {
                            String value_id = reglese.getString("value_id");

                            yzpf = yzpf + value_id + "|";

                        }
                    }
                    if (Objects.equals("角色", param_name)) {
                        String value_text = reglese.getString("value_text");
                        if (des.contains(value_text)) {
                            String value_id = reglese.getString("value_id");

                            sss = sss + value_id + "|";

                            JSONObject data = new JSONObject();
                            data.put("paramId", "7172");
                            data.put("valueId", value_id);
                            dataList.add(data);
                        }
                    }
                    if (Objects.equals("V枪", param_name)) {
                        String value_text = reglese.getString("value_text");
                        if (des.contains(value_text)) {
                            String value_id = reglese.getString("value_id");

                            vss = vss + value_id + "|";

                            JSONObject data = new JSONObject();
                            data.put("paramId", "10731");
                            data.put("valueId", value_id);
                            dataList.add(data);
                        }
                    }
                }
            }
            JSONObject data = new JSONObject();
            data.put("paramId", "7074");
            data.put("valueId", xxjs);
            dataList.add(data);

            JSONObject yzpfdata = new JSONObject();
            yzpfdata.put("paramId", "7171");
            yzpfdata.put("valueId", yzpf);
            dataList.add(yzpfdata);

            JSONObject sssdata = new JSONObject();
            sssdata.put("paramId", "7172");
            sssdata.put("valueId", sss);
            dataList.add(sssdata);

            JSONObject vssData = new JSONObject();
            vssData.put("paramId", "10731");
            vssData.put("valueId", vss);
            dataList.add(vssData);
        }
        extendData.put("params", dataList);
        return extendData;
    }


    private Integer getGame(String game) {

        if (Objects.equals(game, "英雄联盟")) {
            return 10492;
        }
        if (Objects.equals(game, "王者荣耀")) {
            return 10874;
        }
        if (Objects.equals(game, "CF手游")) {
            return 10874;
        }
        if (Objects.equals(game, "和平精英")) {
            return 10877;
        }
        if (Objects.equals(game, "QQ飞车手游")) {
            return 10881;
        }
        if (Objects.equals(game, "CF端游")) {
            return 10895;
        }
        if (Objects.equals(game, "逆战")) {
            return 10898;
        }
        if (Objects.equals(game, "火影忍者")) {
            return 10904;
        }
        if (Objects.equals(game, "原神")) {
            return 19522;
        }
        if (Objects.equals(game, "英雄联盟手游")) {
            return 19792;
        }
        if (Objects.equals(game, "光遇")) {
            return 19929;
        }
        if (Objects.equals(game, "QQ飞车端游")) {
            return 10925;
        }

        return null;

    }

    public String readTxtFile() {

//        ClassPathResource classPathResource = new ClassPathResource("zhuanzhuan.json");

        StringBuffer buffer = new StringBuffer();

//        File file = new File("E:\\img\\zhuan.json");
        File file = new File("/home/zhuan.json");

        String encoding = "utf-8";
        try (InputStreamReader read = new InputStreamReader(new FileInputStream(file), encoding);
             BufferedReader bufferedReader = new BufferedReader(read)) {
            //判断文件是否存在
            if (file.isFile() && file.exists()) {
                String lineTxt;
                while ((lineTxt = bufferedReader.readLine()) != null) {
//                    System.out.println(lineTxt);
                    buffer.append(lineTxt);
                }
            } else {
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return buffer.toString();
    }

    public static void main(String[] args) {
        AccountInfo accountInfo = new AccountInfo();
        accountInfo.setType("王者荣耀");
        accountInfo.setLevel("有二次");
        accountInfo.setDes("xyr24821|21011|【可二次实名】安卓q-108英雄-115皮肤-1内测 玩趣恶龙 拒霜思 猪悟能 猎兽之王 星空之诺 银河之约 冰冠公主 暗影游猎 原初追逐者 黎明之约 死神来了 狂想玩偶喵 曙光守护者 水晶猎龙者 心灵骇客 心灵战警 圣诞狂欢 鬼剑武藏 乘风破浪 幽灵船长 天才门将 金属风暴 偶像歌手 德古拉伯爵 暗隐猎兽者 黄金分割率 缤纷独角兽 猫狗日记女 修罗 无双飞将 未来纪元 地狱火 李小龙 拳王 科学大爆炸 丁香结... 营地ID：522414688|野蛮之锤,无双之魔,剑圣,寂灭之心,断案大师,拳僧,冷晖之枪,爆弹怪猫,万古长明,万物有灵,萤火之旅,永夜之心,暗夜萝莉,万物有灵,惊鸿之笔,仁德义枪,无尽之盾,洛神降临,苍天翔龙,王都密探,圣域余辉,沙海飞舟,沙海飞舟,战车意志,暗夜萝莉,传说之刃,秩序统将,,烈炮小子,冰雪之华,渡世行者,爆弹怪猫,逆流之时,国士无双,星辰之子,月光之女,不屈铁壁,噬灭日蚀,天元之弈,暗影刀锋,双面君主,星辰之子,剑圣,冰雪之华,燃魂重炮,和平守望,千金重弩,暴走机关,神匠,剑圣,叛逆吟游,永恒之月,叛逆吟游,流云之翼,热烈之斧,圣骑之力,信念之刃,鲜血枭雄,桀骜炎枪,玉城之子,玉城之子,拳僧,鹿灵守心,破镜之刃,烈炮小子,幻纱之灵,言灵之书,寒月公主,传说之刃,和平守望,逍遥幻梦,破晓之神,无忧猛士,恋之微风,虚灵城判,至高创世,野蛮之锤,燎原之心,寂灭之心,不屈铁壁,霓裳风华,不屈铁壁,鲨之猎刃,燃魂重炮,野蛮之锤,冰雪之华,善恶怪医,破魔之箭,和平守望,万古长明,森之风灵,拳僧,森之风灵,神匠,静谧之眼,最终兵器,善恶怪医,雷霆之王,虚灵城判,天籁弦音,热烈之斧,精灵之舞,太古魔导,逆流之时,寒月公主,暗影刀锋,仁德义枪,传说之刃,暗影刀锋,根源之目,铁血都督,永恒之月,战车意志,精英酋长,炼金大师,淬命双剑,断案大师,烈炮小子,炼金大师,圣域余辉,流云之翼,拳僧,秩序统将,烈炮小子,圣域余辉,一骑当千,入梦之灵,霸王,六合虎拳,六合虎拳,筑城者,玫瑰剑士,一骑当千,灵魂劫卜,万物有灵,嚣狂之镰,圣域余辉,苍天翔龙,绝代智谋,正义爆轰,正义爆轰,沧海之曜,不羁之风,爆弹怪猫,绝世舞姬,远游之枪,机关造物,恋之微风,恋之微风,最终兵器,断案大师,冷晖之枪,万物有灵,暴走机关,王都密探,无忧猛士,万古长明,无忧猛士,神梦一刀,远游之枪,绝代智谋,,光明之海,信念之刃,根源之目,狂战士,鲜血枭雄,国士无双,万古长明,鹰之守护,苍天翔龙,双面君主,青莲剑仙,无尽之盾,战车意志,仁德义枪,明媚烈焰,,千金重弩,机关造物,灵魂劫卜,鲜血枭雄,沧海之曜,无双之魔,爆弹怪猫,王都密探,叛逆吟游,远游之枪,无双之魔,桀骜炎枪,嚣狂之镰,不羁之风,断案大师,禁血狂兽,逍遥幻梦,幻舞玲珑,禁血狂兽,魅力之狐,洛神降临,千金重弩,半神之弓,燃魂重炮,嚣狂之镰,天元之弈,破灭刃锋,破灭刃锋,霸王,无间傀儡,无间傀儡,齐天大圣,苍天翔龙,齐天大圣,神梦一刀,冰雪之华,断案大师,热烈之斧,双面君主,霸王,暗夜萝莉,魅力之狐,魅力之狐,圣骑之力,圣骑之力");
//        JSONObject jsonObject = extendData(accountInfo);
//        System.out.println(jsonObject);

    }

}
